package com.studyhub.question.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.studyhub.question.model.entity.QueAnswerEntity;
import com.studyhub.question.model.vo.AnswerVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 答案数据访问层
 */
@Mapper
public interface AnswerMapper extends BaseMapper<QueAnswerEntity> {

    /**
     * 查询问题的所有顶级答案（包含用户信息）
     */
    List<AnswerVO> selectTopLevelAnswers(@Param("questionId") Long questionId);

    /**
     * 查询某个答案的子回复（包含用户信息）
     */
    List<AnswerVO> selectChildAnswers(@Param("parentAnswerId") Long parentAnswerId);

    /**
     * 更新答案点赞数
     */
    @org.apache.ibatis.annotations.Update("UPDATE que_answer SET like_count = like_count + #{increment} WHERE answer_id = #{answerId}")
    void updateLikeCount(@Param("answerId") Long answerId, @Param("increment") Integer increment);
}
